package com.zenith.api.controller;

import com.zenith.api.feign.article.ArticleServiceFeignClient;
import com.zenith.common.result.Result;
import com.zenith.common.result.PageResult;
import com.zenith.api.po.dto.article.*;
import com.zenith.api.po.vo.article.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 文章控制器 - API服务
 */
@Slf4j
@RestController
@RequestMapping("/api/article")
@Tag(name = "文章管理", description = "文章管理接口")
@RequiredArgsConstructor
public class ArticleController {
    
    private final ArticleServiceFeignClient articleServiceFeignClient;
    
    // =========================== 文章管理相关接口 ===========================
    
    /**
     * 分页查询文章
     */
    @Operation(summary = "分页查询文章")
    @PostMapping("/getArtArticlePage")
    public Result<PageResult<ArtArticleVO>> getArtArticlePage(@RequestBody ArtArticleDTO query) {
        return articleServiceFeignClient.getArtArticlePage(query);
    }
    
    /**
     * 创建文章
     */
    @Operation(summary = "创建文章")
    @PostMapping("/createArtArticle")
    public Result<Boolean> createArtArticle(@RequestBody ArtArticleDTO articleDTO) {
        return articleServiceFeignClient.createArtArticle(articleDTO);
    }

    /**
     * 更新文章
     */
    @Operation(summary = "更新文章")
    @PostMapping("/updateArtArticle")
    public Result<Boolean> updateArtArticle(@RequestBody ArtArticleDTO articleDTO) {
        return articleServiceFeignClient.updateArtArticle(articleDTO);
    }

    /**
     * 删除文章
     */
    @Operation(summary = "删除文章")
    @PostMapping("/deleteArtArticle/{id}")
    public Result<Boolean> deleteArtArticle(@PathVariable Long id) {
        return articleServiceFeignClient.deleteArtArticle(id);
    }

    /**
     * 发布文章
     */
    @Operation(summary = "发布文章")
    @PostMapping("/publishArtArticle/{id}/publish")
    public Result<Boolean> publishArtArticle(@PathVariable Long id) {
        return articleServiceFeignClient.publishArtArticle(id);
    }

    /**
     * 获取文章详情
     */
    @Operation(summary = "获取文章详情")
    @PostMapping("/getArtArticleDetail/{id}")
    public Result<ArtArticleDTO> getArtArticleDetail(@PathVariable Long id) {
        return articleServiceFeignClient.getArtArticleDetail(id);
    }

    // =========================== 文章分类相关接口 ===========================

    /**
     * 分页查询文章分类
     */
    @Operation(summary = "分页查询文章分类")
    @PostMapping("/category/getArtCategoryPage/page")
    public Result<PageResult<ArtCategoryVO>> getArtCategoryPage(@RequestBody ArtCategoryDTO query) {
        return articleServiceFeignClient.getArtCategoryPage(query);
    }

    /**
     * 获取分类树结构
     */
    @Operation(summary = "获取分类树结构")
    @PostMapping("/category/getArtCategoryTree/tree")
    public Result<ArtCategoryVO> getArtCategoryTree() {
        return articleServiceFeignClient.getArtCategoryTree();
    }

    /**
     * 创建文章分类
     */
    @Operation(summary = "创建文章分类")
    @PostMapping("/category/createArtCategory")
    public Result<Boolean> createArtCategory(@RequestBody ArtCategoryDTO categoryDTO) {
        return articleServiceFeignClient.createArtCategory(categoryDTO);
    }

    /**
     * 更新文章分类
     */
    @Operation(summary = "更新文章分类")
    @PostMapping("/category/updateArtCategory")
    public Result<Boolean> updateArtCategory(@RequestBody ArtCategoryDTO categoryDTO) {
        return articleServiceFeignClient.updateArtCategory(categoryDTO);
    }

    /**
     * 删除文章分类
     */
    @Operation(summary = "删除文章分类")
    @PostMapping("/category/deleteArtCategory/{id}")
    public Result<Boolean> deleteArtCategory(@PathVariable Long id) {
        return articleServiceFeignClient.deleteArtCategory(id);
    }

    // =========================== 文章评论相关接口 ===========================

    /**
     * 创建文章评论
     */
    @Operation(summary = "创建文章评论")
    @PostMapping("/comment/createArtComment")
    public Result<Boolean> createArtComment(@RequestBody ArtCommentDTO comment) {
        return articleServiceFeignClient.createArtComment(comment);
    }

    /**
     * 删除文章评论
     */
    @Operation(summary = "删除文章评论")
    @PostMapping("/comment/deleteArtComment/{id}")
    public Result<Boolean> deleteArtComment(@PathVariable Long id) {
        return articleServiceFeignClient.deleteArtComment(id);
    }

    // =========================== 文章互动相关接口 ===========================

    /**
     * 创建文章互动（点赞、收藏、分享等）
     */
    @Operation(summary = "创建文章互动")
    @PostMapping("/interaction/createArtInteraction")
    public Result<Boolean> createArtInteraction(@RequestBody ArtInteractionDTO interaction) {
        return articleServiceFeignClient.createArtInteraction(interaction);
    }

    /**
     * 删除文章互动
     */
    @Operation(summary = "删除文章互动")
    @PostMapping("/interaction/deleteArtInteraction/{id}")
    public Result<Boolean> deleteArtInteraction(@PathVariable Long id) {
        return articleServiceFeignClient.deleteArtInteraction(id);
    }

    // =========================== 文章标签相关接口 ===========================

    /**
     * 分页查询文章标签
     */
    @Operation(summary = "分页查询文章标签")
    @PostMapping("/tag/getArtTagPage")
    public Result<PageResult<ArtTagVO>> getArtTagPage(@RequestBody ArtTagDTO query) {
        return articleServiceFeignClient.getArtTagPage(query);
    }

    /**
     * 创建文章标签
     */
    @Operation(summary = "创建文章标签")
    @PostMapping("/tag/createArtTag")
    public Result<Boolean> createArtTag(@RequestBody ArtTagDTO tagDTO) {
        return articleServiceFeignClient.createArtTag(tagDTO);
    }

    /**
     * 更新文章标签
     */
    @Operation(summary = "更新文章标签")
    @PostMapping("/tag/updateArtTag")
    public Result<Boolean> updateArtTag(@RequestBody ArtTagDTO tagDTO) {
        return articleServiceFeignClient.updateArtTag(tagDTO);
    }

    /**
     * 删除文章标签
     */
    @Operation(summary = "删除文章标签")
    @PostMapping("/tag/deleteArtTag/{id}")
    public Result<Boolean> deleteArtTag(@PathVariable Long id) {
        return articleServiceFeignClient.deleteArtTag(id);
    }

    // =========================== 文章专题相关接口 ===========================

    /**
     * 分页查询文章专题
     */
    @Operation(summary = "分页查询文章专题")
    @PostMapping("/topic/getArtTopicPage")
    public Result<PageResult<ArtTopicVO>> getArtTopicPage(@RequestBody ArtTopicDTO query) {
        return articleServiceFeignClient.getArtTopicPage(query);
    }

    /**
     * 创建文章专题
     */
    @Operation(summary = "创建文章专题")
    @PostMapping("/topic/createArtTopic")
    public Result<Boolean> createArtTopic(@RequestBody ArtTopicDTO topicDTO) {
        return articleServiceFeignClient.createArtTopic(topicDTO);
    }

    /**
     * 更新文章专题
     */
    @Operation(summary = "更新文章专题")
    @PostMapping("/topic/updateArtTopic")
    public Result<Boolean> updateArtTopic(@RequestBody ArtTopicDTO topicDTO) {
        return articleServiceFeignClient.updateArtTopic(topicDTO);
    }

    /**
     * 删除文章专题
     */
    @Operation(summary = "删除文章专题")
    @PostMapping("/topic/deleteArtTopic/{id}")
    public Result<Boolean> deleteArtTopic(@PathVariable Long id) {
        return articleServiceFeignClient.deleteArtTopic(id);
    }
}